package com.ykdl.member.kid.doctor;

import java.util.jar.Attributes.Name;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.beans.DoctorInfoBean;
import com.ykdl.member.kid.beans.DoctorsBean;
import com.ykdl.member.kid.beans.DoctorsListBean;
import com.ykdl.member.kid.beans.UserActorBean;
import com.ykdl.member.kid.doctor.DoctorListAcivity.getDoctorListTag;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.image.ImageLoader;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.widget.AsyncImageView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;
/**
 * 医生详情Acivity
 * @author chenshuai
 */
public class DoctorInfoActivity extends BaseScreen{
	private String doctorid ="";
	private UserActorBean doctor ;
	private AsyncImageView doctor_head ;
	private TextView doctor_name ,doctor_position,doctor_hospital,doctor_adrr,
	doctor_jianjie,doctor_zhuanye,doctor_gerenxinxi;
	private  String name; 
	private String TAG = "DoctorInfoActivity";
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		name=this.getIntent().getStringExtra("doctor_name");
		setTopTitle("", 0, R.drawable.back_bg, new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				finish();
			}
		}, 0, 0, null, R.drawable.title_bg, false);
		setContent(R.layout.doctorinfoactivity_xml);
		doctorid = this.getIntent().getStringExtra("doctor_id");
		inint();
	}
	public void inint() {
		doctor_head = (AsyncImageView)findViewById(R.id.doctor_head);
		doctor_name = (TextView)findViewById(R.id.doctor_name);
		doctor_position = (TextView)findViewById(R.id.doctor_position);
		doctor_hospital = (TextView)findViewById(R.id.doctor_hospital);
		doctor_adrr = (TextView)findViewById(R.id.doctor_adrr);
		doctor_jianjie = (TextView)findViewById(R.id.doctor_jianjie);
		doctor_zhuanye = (TextView)findViewById(R.id.doctor_zhuanye);
		doctor_gerenxinxi = (TextView)findViewById(R.id.doctor_gerenxinxi);
		inintdata() ;
	}
	public void setData(UserActorBean doctor ) {
		setTopNav(doctor.getDisplay_name());
		if (doctor.getAvatar_file_meta()!=null) {
			String url = doctor.getAvatar_file_meta().getDownload_urls().getBig().getUrl();
			doctor_head.setUrl(TAG, url, 
					ImageOptionsFactory.getSmallPortraitOptions(DoctorInfoActivity.this));
		}
		doctor_name.setText(doctor.getDisplay_name());
		if (doctor.getProfile()!=null) {
			doctor_position.setText(doctor.getProfile().getTitle());
			doctor_hospital.setText(doctor.getProfile().getInstruction());
			doctor_adrr.setText(doctor.getProfile().getDepartment());
			doctor_jianjie.setText(doctor.getProfile().getIntro());
			doctor_zhuanye.setText(doctor.getProfile().getSpecialty());
			doctor_gerenxinxi.setText(doctor.getProfile().getIntroduction());
		}
		
	}
	public void inintdata() {
		showProgress("正在加载中,请稍等...");
		String  pageurl =KidConfig.GET_DOCTOR_INFO+doctorid;
		HttpBaseRequest request  =  Wxxr.getInstance().getBaseRequest(pageurl);
		 TaskManager.startHttpRequest(request, new getDoctorInfoTag(),  DoctorInfoBean.class);
	}
	
	class getDoctorInfoTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof DoctorInfoBean) {
				DoctorInfoBean bean = (DoctorInfoBean)t;
				doctor = bean.getDoctor();
				setData(doctor);
				Toast.makeText(mContext, "加载成功", 1).show();
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().setCurrentActivity(TAG);
		super.onResume();
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().pause(TAG);
		super.onPause();
	}
	
}
